<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="app">
        <reg></reg>
    </div>
    <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
    <script>
        Vue.component("input-element",{
            props:["type","value","info"],
            template:`
                <div>
                    <label><slot></slot></label>
                    <input v-bind:type="type" v-bind:value="value" v-on:blur="$emit('validate',$event)" />
                    <span>{{info}}</span>
                </div>
            `
        });
        Vue.component("reg",{
            template: `
                <div>
                    <h1>注册</h1>    
                    <input-element
                     v-bind:value="username.value"
                     v-bind:info="username.info"
                     @validate="validateUsername"
                    type="text">用户名</input-element>
                    <input-element type="password">密码</input-element>
                    <input-element type="password">确认密码</input-element>
                    <button type="button">注册</button>
                </div>
            `,
            data(){
                return {
                    username:{
                        value:"",
                        info:""
                    }
                }
            },
            methods:{
                validateUsername(e){
                    console.log(e.target.value)
                }
            }
        });
        new Vue({
            el:"#app",

        });
    </script>
</body>
</html>